using System; 
using System.Text; 
using System.Data;
using System.Data.SqlClient;
using System.Data.Common;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Configuration; 
using System.Xml; 
using System.Xml.Serialization;
using SubSonic; 
using SubSonic.Utilities;
namespace LMSData
{

    public partial class GroupController
    {

        public static Group GetGroupByKey(string GroupKey)
        {
            Group org = new Group();
            GroupCollection coll = new GroupCollection();
            Query qry = new Query(Group.Schema);
            qry.AddWhere(Group.Columns.GroupName, GroupKey);
            coll.LoadAndCloseReader(qry.ExecuteReader());
            if (coll.Count > 0) org = coll[0];
            return org;
        }

        public static GroupCollection GetGroups()
        {
            GroupCollection coll = new GroupCollection();
            Query qry = new Query(Group.Schema).WHERE(Group.Columns.IsDeleted, false);
            coll.LoadAndCloseReader(qry.ExecuteReader());
            return coll;
        }

        public static CourseCollection GetCourses(string GroupID)
        {
            CourseGroupMapCollection coll = new CourseGroupMapCollection();
            Query qry = new Query(CourseGroupMap.Schema).WHERE(CourseGroupMap.Columns.GroupID, GroupID);
            coll.LoadAndCloseReader(qry.ExecuteReader());

            CourseCollection cc = new CourseCollection();

            foreach (CourseGroupMap cgm in coll)
            {
                Course crs = new Course(cgm.CourseID);
                if(!crs.IsDeleted)
                    cc.Add(new Course(cgm.CourseID));
            }

            return cc;
        }
    }
}
